package com.xk.school_device.saToken;

import cn.dev33.satoken.stp.StpInterface;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xk.school_device.entity.Users;
import com.xk.school_device.mapper.UsersMapper;
import com.xk.school_device.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title: StpInterfaceImpl
 * @Author xk
 * @Package com.xk.school_device.saToken
 * @Date 2025/4/16 15:16
 * @description: 权限加载实现类
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    /**
     * 返回一个账号所拥有的权限码集合
     */

    @Autowired
    private UsersMapper userMapper;
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 本 list 仅做模拟，实际项目中要根据具体业务逻辑来查询权限
        List<String> list = new ArrayList<String>();
        Users userId = userMapper.selectOne(new QueryWrapper<Users>().eq("user_id", loginId));
        list.add(userId.getRoleId());
        return list;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 本 list 仅做模拟，实际项目中要根据具体业务逻辑来查询角色
        List<String> list = new ArrayList<String>();
        Users userId = userMapper.selectOne(new QueryWrapper<Users>().eq("user_id", loginId));
        list.add(userId.getRoleId());
        return list;
    }

}
